package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

/**
 * @author 十一
 * @Description
 * @create 2020-11-14-15:50
 */
public interface UserMapper extends BaseMapper<User> {
    @Select("select username , password , id from t_user where username = #{username}")
    UserVO finsUserByUsername(@Param("username") String username);

    @Select("select tr.keyword , tr.id " +
            " from t_user_role tur , t_role tr " +
            " where tr.id = tur.role_id and tur.user_id = #{id}")
    Set<RoleVO> findUserRolesByUserId(@Param("id") Integer id);

    @Select("SELECT tp.keyword " +
            "FROM t_permission tp , t_role_permission trp  " +
            "WHERE tp.id = trp.permission_id " +
            "and trp.role_id = #{id}")
    Set<Permission> findPermissionByRoleId(@Param("id") Integer id);
}
